package ms.maplestory.boot.world;

import ms.maplestory.boot.ServerConstants;
import ms.maplestory.boot.client.Account;
import lombok.Getter;
import lombok.Setter;
import ms.maplestory.boot.util.SpringUtil;
import org.springframework.stereotype.Service;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

@Getter
@Setter
@Service
public class LoginServer {

    private int port = ServerConstants.LOGIN_PORT;
    private Set<Integer> accounts = ConcurrentHashMap.newKeySet();

    public static LoginServer getInstance() {
        return SpringUtil.getBean(LoginServer.class);
    }

    public void addAccount(Account account) {
        accounts.add(account.getId());
    }

    public void removeAccount(Account account) {
        accounts.remove(account.getId());
    }

    public void removeAccount(int accountId) {
        accounts.remove(accountId);
    }

    public boolean isAccountLoggedIn(Account account) {
        return accounts.contains(account.getId());
    }
}
